const { ssoLogin } = require("./ssoLogin");
const { codeKeyLogin } = require("./codeKeyLogin");
const { getCategory } = require("./getCategory");
const { ShopCart } = require("./ShopCart");
const { Exchange } = require("./Exchange");
const { UserOrder } = require("./UserOrder");
const { ShopIndex } = require("./ShopIndex");

const serverMap = {
  "/authen/ssoLogin.jsonp": ssoLogin,
  "/User/Login": ({ proxyRes, res, response }) => {
    res.status(200);
    res.setHeader("Content-Type", "application/json");

    return JSON.stringify({
      success: true,
    });
  },
  "/authen/codeKeyLogin.jsonp": codeKeyLogin,
  // 道具列表查询
  "/Shop/Category": getCategory,
  // 添加
  "/Shop/Cart/add/": ({ proxyRes, res, response }) => {
    return JSON.stringify({
      success: true,
      data: response,
    });
  },
  // 删除
  "/Shop/Cart/del/": ({ proxyRes, res, response }) => {
    // if (proxyRes.statusCode === 307) {

    // }
    // 获取重定向的位置
    proxyRes.headers.location = "http://localhost:3000/chdstore/Shop/Cart";
    const location = proxyRes.headers.location;
    proxyRes.statusCode = 200;
    console.log(location, proxyRes.statusCode, "location");
    res.status(200);
    res.setHeader("Content-Type", "application/json");

    return JSON.stringify({
      success: true,
    });
  },
  // 结算查询
  "/Shop/Cart": ShopCart,
  // 购买
  "/Shop/Exchange": Exchange,
  // 订单查询
  "/User/Order": UserOrder,
  // 选区服
  "/User/changearea": ({ proxyRes, res, response }) => {
    return JSON.stringify({
      success: true,
      data: response,
    });
  },
  "/Shop/Index": ShopIndex,
};

module.exports = {
  serverMap,
};
